<?php
header("Content-Type:text/html;charset=utf-8");
require './lib/init.php';

session_start();

// if (!isset($_SESSION['login'])) {
//   echo "<script>window.location.href='login.php'</script>";
//   exit();
// } else {
if (!$_POST) {
  require ROOT . '/view/admin/login.html';
  exit();
}

$username = trim($_POST['username']);
$password = trim($_POST['password']);

if (empty($username)) {
  echo "登录名不能为空！";
  exit();
}

if (empty($password)) {
  echo "密码不能为空！";
  exit();
}

$sql = "select * from user where name='$username' and password='$password'";

$res = mGetRow($sql);
if (!$res) {
  //用户名或密码不存在，弹出‘该用户不存在’
  echo "<script>alert('该用户不存在！');window.location.href='login.php'</script>";
} else {
  //注册新的变量,保存当前会话的昵称
  // echo "<font color=red>登录成功!</font>" ;
  $_SESSION['s_username'] = $username;
  echo "<script>alert('登录成功！');window.location.href='index.php'</script>";
}
// }






// $sql = "select * from user where title='$title'";
// $sql = 'select * from user where name=' . $username . ' and ' . 'password=' . $password;



include(ROOT . '/view/admin/login.html');
